package com.fzj.ssh.controller;

import com.fzj.ssh.domain.SysUser;
import com.fzj.ssh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

/**
 * Created by j on 2016/5/31.
 */

@Controller
@RequestMapping("/front/userController")
public class UserController {
    private UserService userService;

    public UserService getUserSerivce() {
        return userService;
    }

    @Autowired
    public void setUserSerivce(UserService userSerivce) {
        this.userService = userSerivce;
    }

    /**
     * 查询用户
     */
    @RequestMapping(value ="getUser" ,method = RequestMethod.GET)
    public String getUser(String id, HttpServletRequest request){
        SysUser sysUser =userService.getUser(id);
        request.setAttribute("sysUser",sysUser);
        request.setAttribute("msg","查询成功");
        return "result";
    }

    /**
     * 增加用户
     * @param name
     * @param request
     * @return
     */
    @RequestMapping(value = "saveUser", method = RequestMethod.POST)
    public String saveUser(String name, HttpServletRequest request) {
        SysUser sysUser = new SysUser();
        sysUser.setUserId(UUID.randomUUID().toString());
        sysUser.setUserName(name);
        userService.saveUser(sysUser);
        request.setAttribute("sysUser", sysUser);
        request.setAttribute("msg", "添加成功");
        return "result";
    }

}
